package pl.bizuteria.sklep.server.request;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import pl.bizuteria.sklep.api.product.BraceletService;
import pl.bizuteria.sklep.api.product.ClipService;
import pl.bizuteria.sklep.api.product.EaringService;
import pl.bizuteria.sklep.api.product.ProductLocator;
import pl.bizuteria.sklep.api.product.ProductServiceLocator;
import pl.bizuteria.sklep.server.service.BraceletServiceImpl;
import pl.bizuteria.sklep.server.service.ClipServiceImpl;
import pl.bizuteria.sklep.server.service.EaringServiceImpl;

import com.google.web.bindery.requestfactory.server.ServiceLayerDecorator;
import com.google.web.bindery.requestfactory.shared.Locator;
import com.google.web.bindery.requestfactory.shared.ServiceLocator;

public class MojServiceLayerDecorator extends ServiceLayerDecorator {
	
	Logger logger = LoggerFactory.getLogger(MojServiceLayerDecorator.class);
	private Map<Class<?>, Class<?>> objectMap;
	private ProductLocator productLocator;
	private ProductServiceLocator productServiceLocator;
	
	public MojServiceLayerDecorator() {
		objectMap = new HashMap<Class<?>, Class<?>>();
		objectMap.put(EaringService.class, EaringServiceImpl.class);
		objectMap.put(BraceletService.class, BraceletServiceImpl.class);
		objectMap.put(ClipService.class, ClipServiceImpl.class);
	}
	
	@Override
	public <T extends Locator<?, ?>> T createLocator(Class<T> clazz) {
		logger.info("Tworze locatora dla: " + clazz);
		productLocator = new ProductLocator(new CommonService());
		return (T) productLocator;
	}
	
	
	@Override
	public <T extends ServiceLocator> T createServiceLocator(Class<T> clazz) {
		productServiceLocator = new ProductServiceLocator(objectMap);
		return (T) productServiceLocator;
	}
	
	
}
